//和为k的子数组

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        int sum = 0, ret = 0;
        hash[0] = 1;
        for(int i  = 0; i < nums.size();i++)
        {
            sum = sum + nums[i];
            if(hash.count(sum - k) != 0) ret += hash[sum - k];
            hash[sum]++;
        }
        return ret;
    }
};